from datetime import timedelta
from celery import Celery
from celery.schedules import crontab

cel = Celery('tasks',
             broker='redis://127.0.0.1:6379/1',
             backend='redis://127.0.0.1:6379/2',
             include=[
                 'celery_tasks.task01',
                 'celery_tasks.task02',
             ])
cel.conf.timezone = 'Asia/Shanghai'
cel.conf.enable_utc = False

cel.conf.beat_schedule = {
    # 名字随意命名
    'add-every-6-seconds': {
        # 执行tasks1下的test_celery函数
        'task': 'celery_tasks.task02.send_msg',
        # 每隔2秒执行一次
        # 'schedule': 1.0,
        # 'schedule': crontab(minute="*/1"),
        'schedule': timedelta(seconds=2),
        # 传递参数
        'args': ('李四',)
    },
    'add-every-1-minute': {
        'task': 'celery_tasks.task01.send_email',
        # 每分钟执行一次
        'schedule': crontab(minute='*/1'),
        'args': ('张三',)
    },
}
